<template>
  <!-- 设计管理复盘报告 -->
  <base-breadcrumb class="flexMemberInfo-container" :title="titleName" :breadcrumb="!isAudit">
    <a-spin :spinning="loading">
      <a-card>
        <title-name :title="'复盘报告信息'" />

        <custom-form
          ref="form"
          :is-validate="true"
          :edit-model="''"
          :form="form"
          :form-list="formOption"
        />
      </a-card>

      <a-card>
        <title-name :title="'相关附件'" />
        <UploadTableNew
          ref="uploadTable"
          :mode="'add'"
          :disabled="!editable"
          :init-file-list="fileInfoTemp"
          business-code="PM31"
        />
        <p v-if="validate && fileInfoTemp.length == 0" style="color: red;margin: 10px 0 0 0;">请上传相关附件</p>

      </a-card>
    </a-spin>

    <div v-if="!isConsultation" class="pub-header-btn page-btn-right-top">
      <a-button
        v-if="editable"
        :loading="DRAFTLoading"
        type="primary"
        :disabled="SUBMITTEDLoading"
        @click="darft"
      >
        保存草稿
      </a-button>
      <a-button
        v-if="editable"
        :loading="SUBMITTEDLoading"
        :disabled="DRAFTLoading"
        type="primary"
        @click="submit('SUBMITTED')"
      >
        提交
      </a-button>
      <a-button v-checkVisibleInDetail @click="$close"> 关闭 </a-button>
    </div>
    <selectApprover :businessId="businessId"  :processConfig="setProcessConfig"></selectApprover>
  </base-breadcrumb>
  <!-- 设计管理复盘报告 -->
</template>
<script>
import { getReviewReportDetail, updateReviewReport, getReviewReportFileList } from '@/api/design/analyseReport'
// 表单项
const formOption = [
  {
    label: '所属单位',
    keyName: 'viewName',
    type: 'BaseInput',
    disabled: true,
    span: 16
  },
  // {
  //   label: '分公司',
  //   keyName: 'companyName',
  //   type: 'BaseInput',
  //   disabled: true
  // },
  // {
  //   label: '项目名称',
  //   keyName: 'projectName',
  //   type: 'BaseInput',
  //   disabled: true
  // },
  {
    label: '会议名称',
    keyName: 'conferenceName',
    type: 'BaseInput',
    disabled: true
  },
  {
    label: '召开时间',
    keyName: 'conferenceBeginTime',
    type: 'BaseInput',
    disabled: true
  },
  {
    label: '参会人数',
    keyName: 'conferenceNum',
    type: 'BaseInput',
    disabled: true
  }
]
export default {
  name: 'Index',
  components: {
  },
  props: {
    // 是否作为审批详情
    isAudit: {
      type: Boolean,
      default: false
    },
    // 是否作为意见征询
    isConsultation: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    pageType() {
      return this.$route.query.type
    },
    titleName() {
      const obj = { edit: '编辑复盘报告', look: '查看复盘报告' }
      return obj[this.pageType]
    },
    editable() {
      return this.pageType == 'edit'
    },
    fileIds() {
      return this.fileInfoTemp.map(e => e.commonId)
    }
  },
  data() {
    return {
      formOption,
      // 表单
      form: {
        companyName: "",
        conferenceBeginTime: "",
        conferenceName: "",
        conferenceNum: "",
        projectName: "",
        viewName: ""
      },
      loading: false,
      fileInfoTemp: [],
      validate: false,
      DRAFTLoading: false,
      SUBMITTEDLoading: false,
      //获取流程配置值
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      businessId: null
    }
  },
 async mounted() {
    this.getDetail()
    this.processConfig = await this.$getConfigFn('design_management_review')
  },
  methods: {
    getDetail() {
      this.loading = true
      getReviewReportDetail({id: this.$route.query.id}).then((res) => {
        this.loading = false
        if (res.code == 0) {
          this.form = res.data
          this.form.viewName = this.form.companyName + '/' + this.form.projectName
          this.fileInfoTemp = res.data.voList || []
        }
      }).catch(() => {
        this.loading = false
      })
    },
    darft() {
      this.validate = false
      this.request(this.form.conferenceStatus === 'REJECTED' ? this.form.conferenceStatus : 'DRAFT')
    },
    submit(auditStatus) {
      this.validate = true
      this.setProcessConfig = null;
      let that = this
      if (that.fileInfoTemp.length > 0) {
          that.submitApprovalConfirm(auditStatus =='SUBMITTED'?this.processConfig:6, (flag)=>{
          if(!flag) {
                  return
              }
            return that.request('SUBMITTED')
          })
        // this.$confirm({
        //   title: '提示',
        //   content: '确定是否提交？',
        //   okText: '确定',
        //   cancelText: '取消',
        //   onOk() {
        //     return that.request('SUBMITTED')
        //   }
        // })
      }
    },
    api() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({
            code: 200
          })
        }, 2000)
      })
    },
    request(status) {
      const param = {
        conferenceId: this.$route.query.id,
        fileIds: this.fileIds,
        status: status
      }
      const text = status == 'SUBMITTED' ? '提交' : '保存'
      const btnkey = status + 'Loading'
      this[btnkey] = true
      return updateReviewReport(param).then((res) => {
        this[btnkey] = false
        if ((res.code == 0)) {
          this.$message.success(text + '成功')
          if(status == 'SUBMITTED'){
            //提交时，返回id
            this.businessId = res.data.id || this.$route.query.id;
            this.setProcessConfig = this.processConfig;
          }else{
            this.$close() 
          }
        }
      }).catch(() => {
        this[btnkey] = false
      })
    },
    getFileList(params) {
      if (!this.$route.query.id) {
        return Promise.resolve()
      }
      return getReviewReportFileList({ ...params, query: { conferenceId: this.$route.query.id } })
    },
  }
}
</script>
<style lang="scss">
</style>
